lvim.builtin.alpha.active = true
lvim.builtin.alpha.mode = "custom"

local header = {
  type = "text",
  val = require("user.banners"),
  opts = {
    position = "center",
    hl = "Comment",
  },
}

local function button(sc, txt, keybind)
  local sc_ = sc:gsub("%s", ""):gsub("SPC", "<leader>")

  local opts = {
    position = "center",
    text = txt,
    shortcut = sc,
    cursor = 5,
    width = 24,
    align_shortcut = "right",
    hl_shortcut = "Number",
    hl = "Function",
  }
  if keybind then
    opts.keymap = { "n", sc_, keybind, { noremap = true, silent = true } }
  end

  return {
    type = "button",
    val = txt,
    on_press = function()
      local key = vim.api.nvim_replace_termcodes(sc_, true, false, true)
      vim.api.nvim_feedkeys(key, "normal", false)
    end,
    opts = opts,
  }
end

local buttons = {
  type = "group",
  val = {
    button( "f", lvim.icons.ui.FindFile .. "  Find File", "<CMD>Telescope find_files<CR>" ),
    -- button( "n", lvim.icons.ui.NewFile .. "  New File", "<CMD>ene!<CR>" ),
    button( "p", lvim.icons.ui.Project .. "  Projects ", "<CMD>Telescope projects<CR>" ),
    button( "r", lvim.icons.ui.History .. "  Recent files", ":Telescope oldfiles <CR>" ),
    button( "t", lvim.icons.ui.FindText .. "  Find Text", "<CMD>Telescope live_grep<CR>" ),
    button( "c",
    lvim.icons.ui.Gear .. "  Configuration",
    "<CMD>edit " .. require("lvim.config"):get_user_config_path() .. " <CR>"),
    button( "q", lvim.icons.ui.Close .. "  Quit", "<CMD>quit<CR>" ),
  },
  opts = {
    spacing = 1,
  },
}

local fortune = require "alpha.fortune" ()
-- fortune = fortune:gsub("^%s+", ""):gsub("%s+$", "")
local footer = {
  type = "text",
  val = fortune,
  opts = {
    position = "center",
    hl = "Comment",
    hl_shortcut = "Comment",
  },
}

local section = {
  header = header,
  buttons = buttons,
  -- plugin_count = plugin_count,
  -- heading = heading,
  footer = footer,
}

lvim.builtin.alpha.custom = {
  config = {
    layout = {
      { type = "padding", val = 1 },
      section.header,
      { type = "padding", val = 2 },
      section.heading,
      section.plugin_count,
      { type = "padding", val = 1 },
      section.buttons,
      section.footer,
    },
    opts = {
      margin = 5,
    },
  }
}
